// File Terrorist.cpp
//
// Purpose: Class defining the terrorist and his/her data
//
// Author : Bryson King (edited)
// Original Code Provided by: Mat Buckland 2002 (fup@ai-junkie.com)
// Date : 18 March 2013
// --------------------------------------------------------------
#define DEBUG_SECTION

#include "Terrorist.h"

#include <string>
#include <cassert>
#include <iostream>
#include "EntityNames.h"
#include "BaseGameEntity.h"
#include "LocationMachine.h"
#include "Locations.h"
#include "misc/ConsoleUtils.h"
#include "TerroristStates.h"
#include "StateMachine.h"
#include "IPerson.h"
#include "Item.h"

CTerrorist::CTerrorist(int id) : CBaseGameEntity(id), IPerson(), m_iHealth(MaxHealthLevel), m_pCurrentLocation(BoatOutsideShip::Instance())
{
	//set up state machine
	m_pStateMachine = new CStateMachine<CTerrorist>(this);
	m_pLocationMachine = new CLocationMachine(this);
	m_pStateMachine->SetCurrentState(ProceedTowardBridge::Instance());
	m_pLocationMachine->SetCurrentLocation(BoatOutsideShip::Instance());
	// Add terrorist to correct location
	BoatOutsideShip::Instance()->AddEntityToLocation(this);
}

CTerrorist::~CTerrorist()
{
	delete m_pStateMachine;
}

bool CTerrorist::HandleMessage(const Telegram& msg)
{
	return m_pStateMachine->HandleMessage(msg);
}

void CTerrorist::Update()
{
	SetTextColor(FOREGROUND_RED| FOREGROUND_INTENSITY);
	m_pStateMachine->Update();
	m_pLocationMachine->Update();
}

void CTerrorist::CheckInventory()
{
	// Output inventory to console
	SetTextColor(BACKGROUND_BLUE|BACKGROUND_GREEN|BACKGROUND_RED|FOREGROUND_BLUE|FOREGROUND_INTENSITY);
	
	cout << endl;
	cout << "Your inventory contains the following:" << endl;
	cout << endl;
	cout << m_oInventory.ListItems();
	cout << endl;
}

CStateMachine<CTerrorist>* CTerrorist::GetFSM() const
{
	return m_pStateMachine;
}

CLocationMachine* CTerrorist::GetLocationMachine() const
{
	return m_pLocationMachine;
}

std::string CTerrorist::Name() const
{
	return GetNameOfEntity(this->ID());
}

int CTerrorist::GetID() const
{
	return this->ID();
}

//-------------------------------------------------------------accessors
void CTerrorist::SetHealth(int val)
{
	m_iHealth = val;
}
int CTerrorist::Health() const
{
	return m_iHealth;
}
CLocation* CTerrorist::CurrentLocation() const
{
	return m_pCurrentLocation;
}
void CTerrorist::SetNewLocation(CLocation* NewLocation)
{
	m_pCurrentLocation = NewLocation;
}